<?php
namespace Common\Common;

abstract class Object{

    protected $data = [];

    /** @var Model */
    protected $factory;

    public function __construct(array $data, Model $factory = null){
        $this->data = $data;
        $this->factory = $factory;
    }

    public function __get($name){
        $method = '_get'.$name;
        if(method_exists($this,$method))
            return call_user_func([$this, $method]);
        $name = strtolower($name);
        if(isset($this->data))
            return $this->data[$name];
        die('属性不存在，程序错误！');
    }

    public function __set($name, $value){
        $method = '_set'.$name;
        if(method_exists($this,$method))
            return call_user_func([$this, $method], $value);
        $name = strtolower($name);
        if(isset($this->data))
            return $this->data[$name] = $value;
        die('属性不存在，程序错误！');
    }

}